package Interpretor;

import arbori.Nod;
import functii.*;
import functii.elementare.*;
import functii.trigonometrice.*;
import operatori.*;

public class DerivataContext extends Context {
	String result;

	public String getResult() {
		return result;
	}

	public void setResult(String result1) {
		result = result1;
	}

	
	public void actual(Nod nod) {
		if (nod instanceof Plus)
			actual((Plus) nod);
		if (nod instanceof Minus)
			actual((Minus) nod);
		if (nod instanceof Ori)
			actual((Ori) nod);
		if (nod instanceof Impartit)
			actual((Impartit) nod);
		if (nod instanceof Sin)
			actual((Sin) nod);
		if (nod instanceof Cos)
			actual((Cos) nod);
		if (nod instanceof Logaritm)
			actual((Logaritm) nod);
		if (nod instanceof Necunoscuta)
			actual((Necunoscuta) nod);
		if (nod instanceof Constanta)
			actual((Constanta) nod);
		if (nod instanceof Putere)
			actual((Putere) nod);
		if (nod instanceof Radical)
			actual((Radical) nod);
	}

	
	public void actual(Plus plus) {
		if (plus.getFStang() != null && plus.getFDrept() != null) {
			plus.getFStang().interpret(this);
			String s1 = result;
			plus.getFDrept().interpret(this);
			String s2 = result;

			result = plus.concatTermeni(s1, s2);
		}
	}

	
	public void actual(Minus minus) {
		if (minus.getFStang() != null && minus.getFDrept() != null) {
			minus.getFStang().interpret(this);
			String s1 = result;
			minus.getFDrept().interpret(this);
			String s2 = result;

			result = minus.concatTermeni(s1, s2);
		}

	}

	
	public void actual(Ori ori) {
		if (ori.getFStang() != null && ori.getFDrept() != null) {
			ori.getFStang().interpret(this);
			String mult1 = result;
			ori.getFDrept().interpret(this);
			String mult2 = result;
			String res1 = ori.getFStang().toString();
			String res2 = ori.getFDrept().toString();

			result = Plus.ConcatTermeni(Ori.ConcatTermeni(mult1, res2),
					Ori.ConcatTermeni(res1, mult2));
		}
	}

	
	public void actual(Impartit impartit) {
		if (impartit.getFStang() != null && impartit.getFDrept() != null) {
			impartit.getFStang().interpret(this);
			String mult1 = result;
			impartit.getFDrept().interpret(this);
			String mult2 = result;
			String res1 = impartit.getFStang().toString();
			String res2 = impartit.getFDrept().toString();
			if (res2 != "0") {
				result = impartit.ConcatTermeni(Minus.ConcatTermeni(Ori
						.ConcatTermeni(mult1, res2), Ori.ConcatTermeni(res1,
						mult2)), Ori.ConcatTermeni(res2, res2));
			} else {
				System.exit(1);
			}
		}

	}

	
	public void actual(Constanta constanta) {
		result = "0";
	}

	
	public void actual(Logaritm logaritm) {
		// TODO Auto-generated method stub

	}

	
	public void actual(Putere putere) {
		// TODO Auto-generated method stub

	}

	
	public void actual(Radical radical) {
		// TODO Auto-generated method stub

	}

	
	public void actual(Necunoscuta necunoscuta) {
		result = "1";
	}

	
	public void actual(Sin sin) {
		if (sin.getFStang() != null) {
			sin.getFStang().interpret(this);
			String resultT = result;
			String res1 = sin.getFStang().toString();
			result = "-" + Ori.ConcatTermeni(resultT, Cos.ConcatTermeni(res1));
		}
	}

	
	public void actual(Cos cos) {
		if (cos.getFStang() != null) {
			cos.getFStang().interpret(this);
			String resultT = result;
			String res1 = cos.getFStang().toString();
			result = Ori.ConcatTermeni(resultT, Sin.ConcatTermeni(res1));
		}
	}
}
